﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;

namespace QLHPHP
{
    public partial class ChiTietDangKyControl : UserControl
    {
        public ChiTietDangKyControl()
        {
            InitializeComponent();
        }

        private AppCommands _Commands;

        /// <summary>
        /// Gets or sets the commands associated with the control.
        /// </summary>
        public AppCommands Commands
        {
            get { return _Commands; }
            set
            {
                if (value != _Commands)
                {
                    AppCommands oldValue = _Commands;
                    _Commands = value;
                    OnCommandsChanged(oldValue, value);
                }
            }
        }
        /// <summary>
        /// Called when Commands property has changed.
        /// </summary>
        /// <param name="oldValue">Old property value</param>
        /// <param name="newValue">New property value</param>
        protected virtual void OnCommandsChanged(AppCommands oldValue, AppCommands newValue)
        {
            if (newValue != null)
            {
                btnClose.Command = newValue.ChiTietDangKyCommands.Cancel;
               
            }
            else
            {
                btnClose.Command = null; 

            }
        }

        private void ChiTietDangKyControl_Load(object sender, EventArgs e)
        {
            txtSPDK.DataBindings.Add("text", MonHoc.LaySPMax(), "LonNhat");
            int test = int.Parse(txtSPDK.Text);

            int day = DateTime.Now.Day;
            int month = DateTime.Now.Month;
            int year = DateTime.Now.Year;
            string ngaydk = day + "/" + month + "/" + year;

            dgvDSMDDK.DataSource = MonHoc.LayDSMonHocTheoSoPhieuDK(test);
            txtTongTC.DataBindings.Add("Text", MonHoc.TongTCDKTheoSoPhieuDK(test), "TongTCDK");
            txtNgayDK.Text = ngaydk;
            //txtNgayDK.DataBindings.Add("Text", MonHoc.LayThongTinDKChiTietTheoSoPhieuDK(test), "NgayDK");
            txtMSV.DataBindings.Add("Text", MonHoc.LayThongTinDKChiTietTheoSoPhieuDK(test), "MSSV");
            txtHoTen.DataBindings.Add("Text",MonHoc.LayThongTinDKChiTietTheoSoPhieuDK(test),"HoTen");
            txtTiLeGiam.DataBindings.Add("Text",MonHoc.LayThongTinDKChiTietTheoSoPhieuDK(test),"TiLeGiamHocPhi");
            txtGTTC.DataBindings.Add("Text",MonHoc.LayGTTC(),"GTTC");

            int sotc = int.Parse(txtTongTC.Text);
            int gttc = int.Parse(txtGTTC.Text);
            int tongtienphaidong = (sotc * gttc);

            int tlg = int.Parse(txtTiLeGiam.Text);
            int hp = (tongtienphaidong-(tongtienphaidong*tlg)/100);
            txtPhaiDong.Text = hp.ToString();
            int spdk = int.Parse(txtSPDK.Text);
            MonHoc.ThemTienPhaiDongVaoPhieuDK(spdk,hp,0);
            HocPhi.CapNhapThongTinHocPhi();
        }
    }
}
